package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.pojo.TbTypeTemplateExample;
import com.dongdongshop.service.TemplateService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
@DubboService
public class TemplateServiceImpl implements TemplateService {

    @Resource
    private TbTypeTemplateMapper templateMapper;

    //查询全部模板信息
    @Override
    public List<TbTypeTemplate> getTemplateList(String name) {
        TbTypeTemplateExample typeTemplateExample = new TbTypeTemplateExample();
        if (name != null && !"".equals(name)){
            TbTypeTemplateExample.Criteria criteria = typeTemplateExample.createCriteria();
            criteria.andNameLike("%"+name+"%");
        }
        return templateMapper.selectByExample(typeTemplateExample);
    }

    //添加模板信息
    @Override
    public void addTypeTemplate(TbTypeTemplate typeTemplate) {
        templateMapper.insertSelective(typeTemplate);
    }

    //回显模板数据
    @Override
    public TbTypeTemplate getTypeTemplateById(Long id) {
        return templateMapper.selectByPrimaryKey(id);
    }

    //修改操作
    @Override
    public void updateTypeTemplate(TbTypeTemplate typeTemplate) {
        templateMapper.updateByPrimaryKeySelective(typeTemplate);
    }

    //删除操作
    @Override
    public void deleteTypeTemplate(Long[] ids) {
        List<Long> idList = Arrays.asList(ids);
        TbTypeTemplateExample templateExample = new TbTypeTemplateExample();
        TbTypeTemplateExample.Criteria criteria = templateExample.createCriteria();
        criteria.andIdIn(idList);
        templateMapper.deleteByExample(templateExample);
    }
}
